﻿//-----------------------------------------------------------------------
// <copyright file="ChildTemplateWizard.cs" company="Adam Toth">
// Copyright © Adam Toth 2013
// </copyright>
//-----------------------------------------------------------------------
namespace ServiceAppStarterKit.TemplateWizard
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.VisualStudio.TemplateWizard;

    /// <summary>
    /// The Wizard that runs for each child project. Use this to pass variables from the main wizard to child projects.
    /// </summary>
    public class ChildTemplateWizard : IWizard
    {
        /// <summary>
        /// Before opening a file.
        /// </summary>
        /// <param name="projectItem">A project item.</param>
        public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
        {
        }

        /// <summary>
        /// Project finished generating.
        /// </summary>
        /// <param name="project">The project.</param>
        public void ProjectFinishedGenerating(EnvDTE.Project project)
        {
            RootTemplateWizard.SigningManager.AddKeyFile(project);
        }

        /// <summary>
        /// Project item finished generating.
        /// </summary>
        /// <param name="projectItem">The project item.</param>
        public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
        }

        /// <summary>
        /// Run finished.
        /// </summary>
        public void RunFinished()
        {
        }

        /// <summary>
        /// Run started.
        /// </summary>
        /// <param name="automationObject">Automation object.</param>
        /// <param name="replacementsDictionary">The current replacement parameter dictionary.</param>
        /// <param name="runKind">The kind of run.</param>
        /// <param name="customParams">Custom parameters.</param>
        public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            if (replacementsDictionary == null)
            {
                throw new ArgumentNullException("replacementsDictionary");
            }

            replacementsDictionary.Add("$originalprojectname$", RootTemplateWizard.GlobalDictionary["$originalprojectname$"]);
            replacementsDictionary.Add("$originalprojectnameunsafe$", RootTemplateWizard.GlobalDictionary["$originalprojectnameunsafe$"]);
            replacementsDictionary.Add("$servicefeatureguid$", RootTemplateWizard.GlobalDictionary["$servicefeatureguid$"]);
            replacementsDictionary.Add("$servicefeatureitemguid$", RootTemplateWizard.GlobalDictionary["$servicefeatureitemguid$"]);
            replacementsDictionary.Add("$servicepackageguid$", RootTemplateWizard.GlobalDictionary["$servicepackageguid$"]);
            replacementsDictionary.Add("$clientpackageguid$", RootTemplateWizard.GlobalDictionary["$clientpackageguid$"]);
            replacementsDictionary.Add("$webclientsspdata$", RootTemplateWizard.GlobalDictionary["$webclientsspdata$"]);
            replacementsDictionary.Add("$webservicesspdata$", RootTemplateWizard.GlobalDictionary["$webservicesspdata$"]);
            replacementsDictionary.Add("$isapispdata$", RootTemplateWizard.GlobalDictionary["$isapispdata$"]);
            replacementsDictionary.Add("$administrationactionsspdata$", RootTemplateWizard.GlobalDictionary["$administrationactionsspdata$"]);
            replacementsDictionary.Add("$sqlspdata$", RootTemplateWizard.GlobalDictionary["$sqlspdata$"]);
            replacementsDictionary.Add("$adminspdata$", RootTemplateWizard.GlobalDictionary["$adminspdata$"]);
            replacementsDictionary.Add("$adminresourcesspdata$", RootTemplateWizard.GlobalDictionary["$adminresourcesspdata$"]);
            replacementsDictionary.Add("$resourcesspdata$", RootTemplateWizard.GlobalDictionary["$resourcesspdata$"]);
            replacementsDictionary.Add("$serviceguid$", RootTemplateWizard.GlobalDictionary["$serviceguid$"]);
            replacementsDictionary.Add("$serviceproxyguid$", RootTemplateWizard.GlobalDictionary["$serviceproxyguid$"]);
            replacementsDictionary.Add("$serviceinstanceguid$", RootTemplateWizard.GlobalDictionary["$serviceinstanceguid$"]);
            replacementsDictionary.Add("$serviceapplicationguid$", RootTemplateWizard.GlobalDictionary["$serviceapplicationguid$"]);
            replacementsDictionary.Add("$serviceapplicationproxyguid$", RootTemplateWizard.GlobalDictionary["$serviceapplicationproxyguid$"]);
            replacementsDictionary.Add("$databaseguid$", RootTemplateWizard.GlobalDictionary["$databaseguid$"]);
            replacementsDictionary.Add("$wcfserviceguid$", RootTemplateWizard.GlobalDictionary["$wcfserviceguid$"]);
            replacementsDictionary.Add("$servicehostfactoryguid$", RootTemplateWizard.GlobalDictionary["$servicehostfactoryguid$"]);
            replacementsDictionary.Add("$servicecsprojguid$", RootTemplateWizard.GlobalDictionary["$servicecsprojguid$"]);
            replacementsDictionary.Add("$clientcsprojguid$", RootTemplateWizard.GlobalDictionary["$clientcsprojguid$"]);
            replacementsDictionary.Add("$administrationactionscustomactionid$", RootTemplateWizard.GlobalDictionary["$administrationactionscustomactionid$"]);
            replacementsDictionary.Add("$serviceapplicationclassguid$", RootTemplateWizard.GlobalDictionary["$serviceapplicationclassguid$"]);
            replacementsDictionary.Add("$includedb$", RootTemplateWizard.GlobalDictionary["$includedb$"]);
            replacementsDictionary.Add("$customactiongroupid$", RootTemplateWizard.GlobalDictionary["$customactiongroupid$"]);
            replacementsDictionary.Add("$serviceadminfeaturereceiverguid$", RootTemplateWizard.GlobalDictionary["$serviceadminfeaturereceiverguid$"]);
            replacementsDictionary.Add("$registrationspdata$", RootTemplateWizard.GlobalDictionary["$registrationspdata$"]);
            replacementsDictionary.Add("$newserviceapplicationpsguid$", RootTemplateWizard.GlobalDictionary["$newserviceapplicationpsguid$"]);
            replacementsDictionary.Add("$newserviceapplicationproxypsguid$", RootTemplateWizard.GlobalDictionary["$newserviceapplicationproxypsguid$"]);
            replacementsDictionary.Add("$removeservicepsguid$", RootTemplateWizard.GlobalDictionary["$removeservicepsguid$"]);
            replacementsDictionary.Add("$setserviceapplicationpsguid$", RootTemplateWizard.GlobalDictionary["$setserviceapplicationpsguid$"]);
            replacementsDictionary.Add("$setserviceapplicationproxypsguid$", RootTemplateWizard.GlobalDictionary["$setserviceapplicationproxypsguid$"]);
            replacementsDictionary.Add("$spversion$", RootTemplateWizard.GlobalDictionary["$spversion$"]);
            replacementsDictionary.Add("$restserviceguid$", RootTemplateWizard.GlobalDictionary["$restserviceguid$"]);
            replacementsDictionary.Add("$iwcfserviceguid$", RootTemplateWizard.GlobalDictionary["$iwcfserviceguid$"]);
        }

        /// <summary>
        /// Should add project item.
        /// </summary>
        /// <param name="filePath">The path to the file.</param>
        /// <returns>True if the file should be added.</returns>
        public bool ShouldAddProjectItem(string filePath)
        {
            return true;
        }
    }
}